<?php
class model_version extends spModel
{
	protected $version_file_name = 'version_id';
	public $pk = 'uuid';
	public function update($conditions, $row) {
		$count = $this->findCount($conditions);
		if ( $count != 1 )
			throw new Exception("version model can only update one row when call update method");
		//prepare execute insert operation
		unset( $row[$this->version_file_name]);
		$this->model_version_delete_byPk($row[$this->pk]);

		$this->create($row);
	}
	
	public function create($row) {
		if ( !isset($row[$this->pk]) ) {
			$row[$this->pk] = Util::getUUID();	
		}
		$new_inserid = parent::create($row);
		$new_insert_row = $this->findBy($this->version_file_name,$new_inserid);
		return $new_insert_row?$new_insert_row[$this->pk]:NULL;
	}
	public function model_version_delete_byPk($pk,$insertLog = false){
		parent::deleteByPk($pk);
		
		if ( $insertLog ){
		$model_delete_record_log = spClass("model_delete_record_log");
		$row = array(
				'table_name'=>$this->table,
				'uuid'=>$pk
				);
		$model_delete_record_log->create($row);
		}
		
	}
	
}